import { getAddressApi, addAddressApi, updateAddressApi, delAddressApi } from "../../utils/serviceApiUrl.js";
const ADDRESS_LIST = "ADDRESS_LIST";
const state = {
    addressList: null
};

const getters = {
    addressList(state) {
        return state.addressList;
    }
};

const actions = {
    getAddressList({ commit }, param) {
        getAddressApi(param).then((res) => {
            if (res.code == 0) {
                commit(ADDRESS_LIST, res);
            }
        });
    },
    // eslint-disable-next-line no-unused-vars
    getAddressOptions({ commit }, param) {
        return new Promise((resolve, reject) => {
            getAddressApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    },
    // eslint-disable-next-line no-unused-vars
    addAddress({ commit }, param) {
        return new Promise((resolve, reject) => {
            addAddressApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    },
    // eslint-disable-next-line no-unused-vars
    updateAddress({ commit }, param) {
        return new Promise((resolve, reject) => {
            updateAddressApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    },
    // eslint-disable-next-line no-unused-vars
    delAddress({ commit }, param) {
        return new Promise((resolve, reject) => {
            delAddressApi(param).then((res) => {
                if (res.code == 0) {
                    resolve(res.rs);
                } else {
                    reject(res.messages);
                }
            });
        });
    }
};
const mutations = {
    [ADDRESS_LIST](state, data) {
        state.addressList = data.rs;
    }
};

export default {
    state,
    getters,
    actions,
    mutations
};
